import { NoSkinCellRenderer } from "../../common/item/NoSkinCellRenderer";
import { PlayerEvent } from "../../../scene/events/PlayerEvent";
import { SEntityId } from "../../../../../Message/Public/SEntityId";
import { EEntityType } from "../../../../../Message/Public/EEntityType";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { SRobIslandMiniPlayer } from "../../../../../Message/Game/SRobIslandMiniPlayer";
import { ThingUtil } from "../../../scene/layer/utils/ThingUtil";
import { PetIslandUtil } from "../PetIslandUtil";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GBitmap } from "../../../../../com/mui/controls/GBitmap";
import { IEntity } from "../../../scene/player/IEntity";
import { _petIEntity } from "../../../../../this/_petIEntity";
//class PetIslandFightMemberListItemRenderer
    
    export  class PetIslandFightMemberListItemRenderer extends NoSkinCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        /* internal  */onPetEntityInfoUpdateHandler(arg1: PlayerEvent=null): void
        {
            var loc2=null;
            var loc1=arg1 != null ? arg1.player : _petIEntity;
            if (loc1) 
            {
                loc2 = loc1.entityInfo.entityInfo;
                this.lifeBg = loc2.life / loc2.maxLife;
            }
            return;
        }

        /* internal  */set lifeBg(arg1: number)
        {
            this._lifeBg.scaleX = arg1;
            this._lifeTxt.text = int(arg1 * 100) + "%";
            return;
        }

        /* internal  */onLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            var loc1=new SEntityId();
            loc1.type = EEntityType._EEntityTypePlayer;
            loc1.typeEx = this._vo.entityId.typeEx;
            loc1.typeEx2 = this._vo.entityId.typeEx2;
            loc1.id = this._vo.entityId.id;
            Dispatcher.dispatchEvent(new DataEvent(EventName.PetIslandGetPetInfo, loc1));
            return;
        }

        public dispose(): void
        {
            if (this._petIEntity) 
            {
                this._petIEntity.removeEventListener(PlayerEvent.UPDATEINFO, this.onPetEntityInfoUpdateHandler);
            }
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            if (typeof arg1 === "srobislandminiplayer") 
            {
                this.dispose();
                this._vo = arg1 as SRobIslandMiniPlayer;
                this._petIEntity = ThingUtil.sceneEntityUtil.getEntity(this._vo.entityId, PetIslandUtil.MAP_ID);
                if (this._petIEntity) 
                {
                    this._petIEntity.addEventListener(PlayerEvent.UPDATEINFO, this.onPetEntityInfoUpdateHandler);
                    this.onPetEntityInfoUpdateHandler();
                }
                else 
                {
                    this.lifeBg = 0;
                }
                if (this._vo.name != "") 
                {
                    this._name.htmlText = Language.getStringByParam(28109, this._vo.petName);
                }
                else 
                {
                    this._name.htmlText = this._vo.petName;
                }
            }
            return;
        }

        protected /* override */ createChildren(): void
        {
            this._lifeBg = ObjCreate.createGBitmap(ImagesConst.PetIslandFightLifeBg, 0, 0, this);
            this._name = ObjCreate.createGTextField("", 5, 0, 220, 20, this);
            this._name.addEventListener(flash.events.TextEvent.LINK, this.onLinkHandler);
            this._lifeTxt = ObjCreate.createGTextField("", 133, 0, 40, 20, this);
            return;
        }

        protected /* var */_name: GTextFiled;

        protected /* var */_lifeBg: GBitmap;

        protected /* var */_lifeTxt: GTextFiled;

        /* internal */ /* var */_petIEntity: IEntity;

        /* internal */ /* var */_vo: SRobIslandMiniPlayer;
    }
